<?php
require_once 'conf.php';
require_once 'net/crashtoot/php/picasa/model/Album.class.php';
require_once 'net/crashtoot/php/picasa/model/Photo.class.php'; 

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Http_Client_Adapter_Socket'); 
Zend_Loader::loadClass('Zend_Gdata_Photos');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_Photos_UserQuery');
Zend_Loader::loadClass('Zend_Gdata_Photos_AlbumQuery');
Zend_Loader::loadClass('Zend_Gdata_Photos_PhotoQuery');

$username="crashtete-enoha6@yahoo.fr";
$pass="9map174tir"; 

$serviceName = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($username, $pass, $serviceName);

// update the second argument to be CompanyName-ProductName-Version
$gp = new Zend_Gdata_Photos($client, "Google-DevelopersGuide-1.0");


// liste albums

$admin=true;
$albums =  array();
try {
	$query = new Zend_Gdata_Photos_UserQuery();
	$query->setUser($username);

	$userFeed = $gp->getUserFeed(null, $query);
	
	
  $albumEntry = $userFeed[0];
  $album = Album::createAlbum($albumEntry);
	print_r($gp);
  //echo $album->getThumbnailUrl()."<br><br>";
  //echo "<img src='".$album->getThumbnailUrl()."' /><br><br>";
  //echo $album->getTitle();
	//http://lh3.ggpht.com/_1QmCaX6Ds7Y/S-24WEBqW9E/AAAAAAAAAVY/XuZBpVWO1eA/s160-c/Enoha11eMois.jpg
	//http://lh4.ggpht.com/_1QmCaX6Ds7Y/S-28RVGdrPI/AAAAAAAAARg/pI_GNGDsDkc/s72/dscf2840.jpg
	//http://lh4.ggpht.com/_1QmCaX6Ds7Y/S-28eFuWdOI/AAAAAAAAARs/MtRqXv7FE-s/s160/DSCF2867.JPG
	
	//$album->albumEntry->title->text = "Enoha 11e mois 3";
	//$album->albumEntry->save();
	// Enoha 11e mois
	//$album->setTitle("Enoha 11e mois");
	//$album->setThumbnailUrl("http://lh4.ggpht.com/_1QmCaX6Ds7Y/S-28eFuWdOI/AAAAAAAAARs/MtRqXv7FE-s/s160/DSCF2867.JPG");
	
} catch (Exception $e) {
	echo "Error: getAlbums($username, $admin) : " . $e->getMessage() . "<br />\n"; 
}

// liste photos             
/*
$query = $gp->newAlbumQuery();

$query->setUser("default");
$query->setAlbumName("Enoha11eMois");
$query->setImgMax("d");

$albumFeed = $gp->getAlbumFeed($query);

print_r($albumFeed[4]);
$photoEntry = $albumFeed[4];

$albumId = $photoEntry->getGphotoAlbumId()->getText();
$photoId = $photoEntry->getGphotoId()->getText();

$camera = "";
$contentUrl = "";
$firstThumbnailUrl = "";

$albumId = $photoEntry->getGphotoAlbumId()->getText();
$photoId = $photoEntry->getGphotoId()->getText();

if ($photoEntry->getExifTags() != null && 
    $photoEntry->getExifTags()->getMake() != null &&
    $photoEntry->getExifTags()->getModel() != null) {

    $camera = $photoEntry->getExifTags()->getMake()->getText() . " " . 
              $photoEntry->getExifTags()->getModel()->getText();
}

if ($photoEntry->getMediaGroup()->getContent() != null) {
  $mediaContentArray = $photoEntry->getMediaGroup()->getContent();
  $contentUrl = $mediaContentArray[0]->getUrl();
}

if ($photoEntry->getMediaGroup()->getThumbnail() != null) {
  $mediaThumbnailArray = $photoEntry->getMediaGroup()->getThumbnail();
  $firstThumbnailUrl = $mediaThumbnailArray[0]->getUrl();
}

echo "AlbumID: " . $albumId . "<br />\n";
echo "PhotoID: " . $photoId . "<br />\n";
echo "Camera: " . $camera . "<br />\n";
echo "Content URL: <a href='".$contentUrl."' target='_blank'>".$contentUrl."</a><br />\n";
echo "First Thumbnail: <a href='".$firstThumbnailUrl."' target='_blank'>".$firstThumbnailUrl."</a><br />\n";

echo "<br />\n"; 
*/
/*
foreach ($albumFeed as $albumEntry) {
    echo $albumEntry->title->text . "<br />\n";
}*/
 
  
// test sql
//require_once('bootstrap.php');
//echo Doctrine_Core::getPath();

 /*                                
// At this point no actual connection to the database is created
$conn = Doctrine_Manager::connection('mysql://jboz_admin:9map174tir@localhost/jboz_picasa', 'connection test');
// The first time the connection is needed, it is instantiated
// This query triggers the connection to be created
$conn->export->createTable('test', array('name' => array('type' => 'string')));
$conn->execute('INSERT INTO test (name) VALUES (?)', array('jwage'));

//$stmt = $conn->prepare('SHOW TABLES');
$stmt = $conn->prepare('SELECT * FROM test');
$stmt->execute();
$results = $stmt->fetchAll();
print_r($results);

$conn->execute('DROP TABLE test');
                                
$dbName = "jboz_picasa";
$pathToModel = dirname(__FILE__).'/test';
Doctrine_Core::dropDatabases($dbName);
Doctrine_Core::createDatabases($dbName);                                
Doctrine_Core::generateYamlFromModels('test/schema.yml', $pathToModel);
Doctrine_Core::createTablesFromModels($pathToModel);
*/

?>